package com.css.fxfzaqbz.modules.base.repository.impl;

import com.css.fxfzaqbz.modules.assess1.entity.AlgEntity;
import com.css.fxfzaqbz.modules.base.entity.SeismicResult;
import com.css.fxfzaqbz.modules.base.repository.SeismicResultRepository;
import org.springframework.jdbc.core.BeanPropertyRowMapper;
import org.springframework.jdbc.core.JdbcTemplate;
import org.springframework.jdbc.core.namedparam.BeanPropertySqlParameterSource;
import org.springframework.jdbc.core.namedparam.NamedParameterJdbcTemplate;
import org.springframework.jdbc.core.namedparam.SqlParameterSource;
import org.springframework.stereotype.Repository;

import javax.annotation.Resource;
import java.util.List;

@Repository
public class SeismicResultRepositoryImpl implements SeismicResultRepository {
    @Resource
    JdbcTemplate jdbcTemplate;
    @Resource
    NamedParameterJdbcTemplate namedParameterJdbcTemplate;
    @Override
    public void save(SeismicResult seismicResult) {
        String sql="insert into sys_seismic_result values(:id, :iaId,:lieDu, :province, :city, :prefecture, :res,:delFlag, :createTime, :createUser, :updateTime, :updateUser, ST_GeometryFromText(:geom,4490),:number,:corrected,:resultAnalysis)";
        SqlParameterSource source = new BeanPropertySqlParameterSource(seismicResult);
        namedParameterJdbcTemplate.update(sql, source);
    }

    @Override
    public void delete(String iaId) {
        String sql="delete from sys_seismic_result where ia_id=:iaId";
        SqlParameterSource source = new BeanPropertySqlParameterSource(iaId);
        namedParameterJdbcTemplate.update(sql, source);
    }

    @Override
    public List<SeismicResult> getById(String id) {
        String sql="select * from sys_seismic_result where result_analysis = '"+id+"'";
        List<SeismicResult> query = jdbcTemplate.query(sql, new BeanPropertyRowMapper<>(SeismicResult.class));
        return query;

    }

    @Override
    public List<AlgEntity> getData(String id) {
        String sql="select * from sys_destory_alg where result_analysis = '"+id+"'";
        List<AlgEntity> query = jdbcTemplate.query(sql, new BeanPropertyRowMapper<>(AlgEntity.class));
        return query;
    }

}
